package com.example.homework.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.homework.MainActivity;
import com.example.homework.R;
import com.example.homework.utils.MySQLiteOpenHelper;

public class UpdateActivity extends AppCompatActivity {
    private EditText username2, password2, newPassword2;
    private Button buttonUpdate;
    private MySQLiteOpenHelper mySQLiteOpenHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update);
        mySQLiteOpenHelper = new MySQLiteOpenHelper(this);
        username2 = findViewById(R.id.account1);
        password2 = findViewById(R.id.password2);
        newPassword2 = findViewById(R.id.password3);
        buttonUpdate = findViewById(R.id.login2);
        buttonUpdate.setOnClickListener(view -> {
                    String s1 = username2.getText().toString();
                    String s2 = password2.getText().toString();
                    String s3 = newPassword2.getText().toString();
                    int update = mySQLiteOpenHelper.update(s1, s2, s3);
                    if (update != -1) {
                        Toast.makeText(this, "密码修改成功！", Toast.LENGTH_SHORT).show();
                        Intent intentLogin = new Intent(this, LoginActivity.class);
                        startActivity(intentLogin);
                    } else {
                        Toast.makeText(this, "密码修改失败！", Toast.LENGTH_SHORT).show();
                    }
                }
        )
        ;
    }

}